# !/usr/bin/env python
# -*- coding: utf-8 -*-
#  test.py
#  description

#  Created by zhouzongli633 on 2020/6/3 10:10 上午.
#  Copyright ©Intellectus All rights reserved.
import sys

import requests

# import django
# BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# sys.path.append(BASE_DIR)
# os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'NICU2HOME.settings_loc')
# django.setup()
# from User.models import Comments
# from Baby.models import Users


# def foreign_k():
# comment = Comments.objects.get(id=1)
# u = comment.user
#
# user = Users.objects.get(id=1)
# c = user.comments.first()

baby_sence_url = 'https://babysense-staging.fsm.northwestern.edu'
# baby_sence_id = '6b7dddd7-cfbb-44d3-a18a-9e11378dc9ca'
# baby_sence_id = 'fb953a67-439d-4b27-bc62-c45167b05c7b'
baby_sence_id = 'f6356cd2-7614-489e-9e38-61a441551ce5'

mrn = '111013223795'


def call_baby_sence_post(uri, data):
    url = baby_sence_url + uri
    headers = {"Content-Type": "application/json"}
    print(f"url:{url}")
    print(f"data:{data}")
    resp = requests.post(url=url, json=data, headers=headers)
    print(f"resp:{resp}")
    print(type(resp.json()))
    print(resp.json())
    with open("{}.txt".format(uri.replace('/', '-')), 'w') as file_object:
        file_object.write(f"URL:{url} \n")
        file_object.write(f"data:{data}\n")
        file_object.write(resp.text)


def call_baby_sence_put(uri, data):
    url = baby_sence_url + uri

    headers = {"Content-Type": "application/json"}
    print(f"url:{url}")
    print(f"data:{data}")
    resp = requests.put(url=url, json=data, headers=headers)
    print(f"resp:{resp}")
    print(type(resp.json()))
    print(resp.json())
    with open("{}.txt".format(uri.replace('/', '-')), 'w') as file_object:
        file_object.write(f"URL:{url} \n")
        file_object.write(f"data:{data}\n")
        file_object.write(resp.text)


if __name__ == "__main__":
    uri = None
    data = {}
    # arg = sys.argv[1]
    in_put = input("input uri code:")
    arg = int(in_put)
    if arg == 1:
        uri = '/baby'  # create_baby   -post
        data = {
            "first_name": 'Boy Lauren',
            "last_name": "Selman",
            "birthday": "2020-09-19",
            "gender": "male",
            "mrn": mrn,
        }
        call_baby_sence_post(uri=uri, data=data)
    elif arg == 2:
        uri = '/baby/3'  # update_baby   ---put (only update gender)
        data = {
            "gender": "male",
            "babysense_id": baby_sence_id,
        }
        call_baby_sence_put(uri=uri, data=data)
    elif arg == 3:
        uri = '/check'  # check_mrn
        data = {"mrn": "111013223795"}
        call_baby_sence_post(uri=uri, data=data)

    elif arg == 4:
        uri = '/baby/daily_update'  # daily_update
        data = {"babysense_id": "2bb7f51c-2201-4373-8bad-e3810b79e154"}
        call_baby_sence_post(uri=uri, data=data)

    elif arg == 5:
        uri = '/baby/phase'  # phase
        data = {"babysense_id": "2bb7f51c-2201-4373-8bad-e3810b79e154"}
        call_baby_sence_post(uri=uri, data=data)

    elif arg == 6:
        uri = '/baby/procedures'  # procedures
        data = {"babysense_ids": ["2bb7f51c-2201-4373-8bad-e3810b79e154"]}
        call_baby_sence_post(uri=uri, data=data)

    elif arg == 7:
        uri = '/baby/weight'  # weight
        data = {"babysense_id": "2bb7f51c-2201-4373-8bad-e3810b79e154"}
        call_baby_sence_post(uri=uri, data=data)

    elif arg == 8:
        uri = '/baby/height'  # height
        data = {"babysense_id": "2bb7f51c-2201-4373-8bad-e3810b79e154"}
        call_baby_sence_post(uri=uri, data=data)

    elif arg == 9:
        uri = '/baby/head_cir'  # head_cir
        data = {"babysense_id": "2bb7f51c-2201-4373-8bad-e3810b79e154"}
        call_baby_sence_post(uri=uri, data=data)

    elif arg == 10:
        uri = '/baby/nicu_journey_list'  # nicu_journey_list
        data = {"babysense_id": "2bb7f51c-2201-4373-8bad-e3810b79e154"}
        call_baby_sence_post(uri=uri, data=data)

    elif arg == 11:
        uri = '/baby/nicu_journey_data'  # nicu_journey_data
        data = {"babysense_id": "2bb7f51c-2201-4373-8bad-e3810b79e154"}
        call_baby_sence_post(uri=uri, data=data)

    elif arg == 12:
        uri = '/baby/milestones_data'  # milestones_data
        data = {"babysense_id": "2bb7f51c-2201-4373-8bad-e3810b79e154", "milestone_ids": [12, 23, 34]}
        call_baby_sence_post(uri=uri, data=data)

    elif arg == 13:
        uri = '/baby/nicu_journey_add'  # nicu_journey_add
        data = {
            "babysense_id": "2bb7f51c-2201-4373-8bad-e3810b79e154",
            "image_file": None,
            "baby_id": "15",
            "user_id": "13",
            "date": "2019-01-09",
            "type": "kangaroo_cuddle_mom",  # This item is very important and is fetched from the nicu_journey_list
            "input_text": "My baby is recovering really well!"  # Only send this when  "input": true,
        }
        call_baby_sence_post(uri=uri, data=data)

    elif arg == 14:
        uri = '/baby/nicu_journey_delete'  # nicu_journey_delete
        data = {"babysense_id": "2bb7f51c-2201-4373-8bad-e3810b79e154"}
        call_baby_sence_post(uri=uri, data=data)

    elif arg == 15:
        uri = '/baby/name'  # update name   -post
        data = {
            "babysense_id": "6b7dddd7-cfbb-44d3-a18a-9e11378dc9ca",
            "name": "Andy"
        }
        call_baby_sence_post(uri=uri, data=data)

    elif arg == 16:
        uri = '/baby/delete'  # post
        data = {
            "babysense_id": baby_sence_id,
        }
        call_baby_sence_post(uri=uri, data=data)

# 6b7dddd7-cfbb-44d3-a18a-9e11378dc9ca  111013223795   correct
# 2bb7f51c-2201-4373-8bad-e3810b79e154

'''
curl --insecure -X POST \
  https://babysense-staging.fsm.northwestern.edu/baby/daily_update \
  -H 'Content-Type: application/json' \
  -d '{
  "babysense_id": "2bb7f51c-2201-4373-8bad-e3810b79e154"
}'

curl --insecure -X POST https://babysense-staging.fsm.northwestern.edu/baby \
  -H 'Content-Type: application/json' \
  -d '{"first_name": 'Boy Lauren', "last_name": "Selman", "birthday": "2020-09-19", "gender": "male", "mrn": "111013223795"
}'


curl --insecure -X POST https://babysense-staging.fsm.northwestern.edu/baby/delete \
  -H 'Content-Type: application/json' \
  -d '{  
  "babysense_id": "6b7dddd7-cfbb-44d3-a18a-9e11378dc9ca"
}'
'''
